﻿/* Copyright 2008 dnAnalytics Project.
 *
 * Contributors to this file:
 * Patrick van der Velde
 * Marcus Cuda
 * Jurgen Van Gael - http://mlg.eng.cam.ac.uk/jurgen/
 *
 * This file is part of dnAnalytics.  dnAnalytics is licensed under the 
 * Microsoft Public License. See License.txt for a complete copy of the
 * license.
 */
using System;
using dnAnalytics.Properties;

namespace dnAnalytics
{
    /// <summary>
    /// Sets parameters for the library.
    /// </summary>
    public static partial class Control
    {
        private static int mRngBufferSize = 256;

        /// <summary>
        /// Gets or sets the size of the random number buffer used by the native 
        /// random number generators.  A single call to the native RNG is expansive, so
        /// we return multiple random number generators with each call. This property
        /// sets then size of the buffer used.
        /// </summary>
        /// <value>The size of the random number buffer used by the native random number generators. If the value is to a 
        /// non-positive number, one is used.</value>
        /// <remarks>The default buffer size is 256.</remarks>
        public static int RandomNumberGeneratorBufferSize
        {
            get { return mRngBufferSize; }
            set { mRngBufferSize = value < 2 ? 1 : value; }
        }

        /// <summary>Suggests to the runtime the maximum number of threads to use.</summary>
        /// <param name="numThreads">Number of threads suggested.</param>
        /// <exception cref="ArgumentException">If the number of threads is a nonpositive integer.</exception>
        public static void SetNumberThreads(int numThreads)
        {
            if (numThreads < 1)
            {
                throw new ArgumentException("numThreads", Resources.NotPositive);
            }

            SafeNativeMethods.SetNumberThreads(numThreads);
        }
    }
}